package cn.skter.common.ffmpeg;

import cn.hutool.http.HttpUtil;

import java.io.File;
import java.io.IOException;

/***
 * @ClassName TestController
 * @Author Eureka
 * @Description // 测试
 * @Date 2022/4/28 9:47
 * @Version V1.0
 **/
public class TestController {

    public static void main(String[] args) throws IOException {
        String h265Path = "http://192.168.0.68:9090/view/name/0d7edaf9b55942ceba7f2280516a2539.mp4";
        String h264Path = "http://192.168.0.68:9090/view/name/5c07912f41be4971b34384d42e5e2969.mp4";

        //临时文件
        String path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "tmp.mp4";
        File tmpFile = new File(path);
        //下载h265视频
        HttpUtil.downloadFileFromUrl(h265Path, tmpFile);
        System.out.println("下载的视频是否是H264:" + FFmpegUtil.isH264(tmpFile.getPath()));

        //FFmpeg转换
        String ffmpegPath = System.getProperty("user.dir") + File.separator + "ffmpeg-5.0.1" + File.separator + "bin" + File.separator + "ffmpeg.exe";
        String targetPath1 = System.getProperty("user.dir") + File.separator + "target" + File.separator + "video1.mp4";
        FFmpegUtil.ffToMp4(ffmpegPath, path, targetPath1);
        System.out.println("FFmpeg转换后的视频是否是H264:" + FFmpegUtil.isH264(targetPath1));

        //FFmpegFrameGrabber转换
        String targetPath2 = System.getProperty("user.dir") + File.separator + "target" + File.separator + "video2.mp4";
        FFmpegUtil.fffgToMp4(tmpFile.getPath(), targetPath2);
        System.out.println("FFmpegFrameGrabber转换后的视频是否是H264:" + FFmpegUtil.isH264(targetPath2));

    }

}
